package com.justcan.demo.cartoon.libgdx;

import android.graphics.PointF;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Scaling;
import com.badlogic.gdx.utils.viewport.Viewport;

import java.math.BigDecimal;

/**
 * Created by justcan on 2018/1/22.
 */

public class MainStage extends Stage {
    private Texture texture;
    private TextureRegion textureRegion;
    private Image bgImage;


    public MainStage(Viewport viewport) {
        super(viewport);
        initView();
    }

    private void initView() {
        texture = new Texture(Gdx.files.internal("main_bg.jpg"));
        double scaleWith = new BigDecimal(Gdx.graphics.getWidth()).divide(new BigDecimal(texture.getWidth()), 3, BigDecimal.ROUND_HALF_UP).doubleValue();
        double scaleHeight = new BigDecimal(Gdx.graphics.getHeight()).divide(new BigDecimal(texture.getHeight()), 3, BigDecimal.ROUND_HALF_UP).doubleValue();
        textureRegion = new TextureRegion(texture);
        bgImage = new Image(textureRegion);
        bgImage.setSize(getWidth(), getHeight());
        if (scaleWith > scaleHeight) {
            bgImage.setScaling(Scaling.fillX);
        } else {
            bgImage.setScaling(Scaling.fillY);
        }
        bgImage.setAlign(Align.bottomLeft);
        this.addActor(bgImage);
    }

}
